package com.pz.cloud.framework.glory.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.pz.cloud.framework.business.glory.entity.GloryApply;
import com.pz.cloud.framework.business.glory.service.IGloryApplyService;
import com.pz.cloud.framework.business.workflow.annotation.AssembleApproveRecord;
import com.pz.cloud.framework.business.workflow.annotation.AssembleDealFlag;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.aspect.annotation.PermissionData;
import org.jeecg.common.system.base.controller.BaseController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;


@RequestMapping("gloryApply")
@RestController
@Api(tags = "荣誉申请")
@Slf4j
public class GloryApplyController extends BaseController<GloryApply, IGloryApplyService> {
    /**
     * 分页列表查询
     */
    @AutoLog(value = "荣誉申请-分页列表查询")
    @ApiOperation(value = "荣誉申请-分页列表查询", notes = "荣誉申请-分页列表查询")
    @GetMapping(value = "/list")
    @PermissionData(pageComponent = "honor/HonorApply")
    @AssembleDealFlag
    public Result<IPage<GloryApply>> list(GloryApply entity) {
        Result<IPage<GloryApply>> result = new Result<>();
        IPage<GloryApply> pageList = service.findPage(entity);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /**
     * 添加
     * @return
     */
    @AutoLog(value = "荣誉申请-添加|编辑")
    @ApiOperation(value = "荣誉申请-添加|编辑", notes = "荣誉申请-添加|编辑")
    @PostMapping(value = "/add")
    public Result add(@RequestBody GloryApply entity) {
        Result<GloryApply> result = new Result<>();
        service.add(entity);
        result.success("保存成功！");
        return result;
    }


    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "荣誉申请-通过id删除")
    @ApiOperation(value = "荣誉申请-通过id删除", notes = "荣誉申请-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result delete(@ApiParam(required = true) @RequestParam(name = "id") String id) {
        service.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "荣誉申请-批量删除")
    @ApiOperation(value = "荣誉申请-批量删除", notes = "荣誉申请-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public Result deleteBatch(@ApiParam(required = true) @RequestParam(name = "ids") String ids) {
        Result<GloryApply> result = new Result<GloryApply>();
        if (ids == null || "".equals(ids.trim())) {
            result.error500("参数不识别！");
        } else {
            service.removeByIds(Arrays.asList(ids.split(",")));
            result.success("删除成功!");
        }
        return result;
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "荣誉申请-通过id查询")
    @ApiOperation(value = "荣誉申请-通过id查询", notes = "荣誉申请-通过id查询")
    @GetMapping(value = "/queryById")
    @AssembleApproveRecord
    public Result<GloryApply> queryById(@ApiParam(required = true) @RequestParam(name = "id") String id) {
        Result<GloryApply> result = new Result<GloryApply>();
        GloryApply GloryApply = service.getById(id);
        if (GloryApply == null) {
            result.error500("未找到对应实体");
        } else {
            result.setResult(GloryApply);
            result.setSuccess(true);
        }
        return result;
    }

    /**
     * 导出excel
     *
     * @param request
     */
    @RequestMapping(value = "/exportXls")
    @PermissionData(pageComponent = "honor/HonorApply")
    public ModelAndView exportXls(HttpServletRequest request, GloryApply GloryApply) {
        return super.exportXls(request, GloryApply, GloryApply.class, "荣誉申请");
    }

}
